package com.cinema.service;

import com.cinema.entity.movie.Movie;
import com.cinema.util.DataStore;

import java.util.List;

/**
 * 影片服务类，处理影片相关业务逻辑
 */
public class MovieService {
    private final DataStore dataStore = DataStore.getInstance();
    private final List<Movie> movieList = dataStore.getMovieList();

    /**
     * 查找所有影片
     */
    public void listAllMovies() {
        if (movieList.isEmpty()) {
            System.out.println("❌ 暂无影片数据");
            return;
        }

        System.out.println("\n===== 影片列表 =====");
        for (Movie movie : movieList) {
            System.out.println(movie + "\n");
        }
    }

    /**
     * 根据ID查找影片
     */
    public Movie findMovieById(String movieId) {
        for (Movie movie : movieList) {
            if (movie.getMovieId().equals(movieId)) {
                return movie;
            }
        }
        return null;
    }

    /**
     * 添加影片
     */
    public void addMovie(Movie movie) {
        movieList.add(movie);
        dataStore.updateMovieList();
    }

    /**
     * 删除影片
     */
    public boolean deleteMovie(String movieId) {
        Movie movie = findMovieById(movieId);
        if (movie != null) {
            movieList.remove(movie);
            dataStore.updateMovieList();
            return true;
        }
        return false;
    }
}

